<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="${pageContext.response.locale}" lang="${pageContext.response.locale}">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" href="<c:url value="/styles/default.css"/>" type="text/css"/>
        <security:authorize ifNotGranted="ROLE_ADMIN"><style> a:link, a:hover, a:active, a:visited, h1, h2 { color: orange; } </style></security:authorize>
    </head>
    <body>
        <div id="main_wrapper">
            <%@include file="jspf/header.jspf" %>
            <h1><spring:message code="machine.heading"/></h1>
            <security:authorize ifAllGranted="ROLE_ADMIN">
            <a id="new" href="machine/new"><spring:message code="new"/></a>
            </security:authorize>
            <table>
                <tr>
                    <th>Id</th>
                    <th><spring:message code="table.header.licensePlate"/></th>
                    <th class="spread"><spring:message code="table.header.type"/></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                </tr>
                <c:forEach items="${machines}" var="machine">
                    <tr>
                        <td><c:out value="${machine.id}" /></td>
                        <td><c:out value="${machine.licensePlate}" /></td>
                        <td class="spread"><c:out value="${machine.type}" /></td>
                        <td align="right"><a href="machine/${machine.id}/details"><spring:message code="table.row.details"/></a></td>
                        <security:authorize ifAllGranted="ROLE_ADMIN">
                        <td><a href="rental/new?concreteMachineId=${machine.id}"><spring:message code="table.row.rent"/></a></td>
                        <td><a href="machine/${machine.id}/edit"><spring:message code="table.row.edit"/></a></td>
                        <td><a href="machine/${machine.id}/delete"><spring:message code="table.row.delete"/></a></td>
                        </security:authorize>
                        <security:authorize ifNotGranted="ROLE_ADMIN">
                        <td colspan="3"></td>
                        </security:authorize>
                    </tr>
                </c:forEach>
            </table>
            <% if (request.getParameter("error") != null) out.print("<h3>Error: " + request.getParameter("msg") + "</h3>"); %>
            <% if (request.getParameter("success") != null) out.print("<h3><spring:message code=\"operation.success\"/></h3>"); %>
        </div>
    </body>
</html>
